<template>
  <a-modal title-align="start" title="批量接/拒单" :mask-closable="false" v-model:visible="showvisible" @cancel="showvisible = false" :width="400">
    <a-radio-group v-model="accept">
      <a-radio :value="true">确认接单</a-radio>
      <a-radio :value="false">拒绝接单</a-radio>
    </a-radio-group>
    <div class="mt10" v-if="!accept">
      <a-textarea v-model="remark" placeholder="请输入原因" />
    </div>

    <template #footer class="modal-footer">
      <a-button @click="showvisible = false">取消</a-button>
      <a-button type="primary" :loading="loading" @click="submit">确定</a-button>
    </template>
  </a-modal>
</template>

<script lang="ts" setup>
  import { defineComponent, ref, computed } from 'vue'
  import { Message } from '@arco-design/web-vue'
  import { batchSupplierTake } from '@/api/purchase'
  let props = defineProps(['modelValue', 'ids'])
  let emits = defineEmits(['save', 'update:modelValue'])
  let showvisible = computed({
    get() {
      return props.modelValue
    },
    set(val) {
      emits('update:modelValue', val)
    },
  })

  let remark = ref('')
  let loading = ref(false)
  let accept = ref(true)
  const submit = async () => {
    if (!accept.value && !remark.value) return Message.error('请填写原因')
    let params = {
      accept: accept.value,
      idList: props.ids,
      rejectReason: remark.value,
    }

    try {
      const res: any = await batchSupplierTake(params)
      if (res) {
        Message.success(`${accept.value ? '接单' : '拒绝接单'}成功`)
        emits('save')
        showvisible.value = false
      }
    } catch (error) {}
    loading.value = false
  }
</script>

<style lang="less" scoped></style>
